<template>
	<uni-section title="" type="line">
		<uni-list>
			<uni-list-item v-for="item in listData" :title="item.orderContext" :rightText="item.createDatetime"
				link="navigateTo" :to="'/pages/process-work-order/alreadydone?type=todo&id=' + item.id" :key="item.id"
				showArrow  />
		</uni-list>
	</uni-section>
	<div class="space"></div>
	<uni-pagination title="标题文字" prev-text="前一页" next-text="后一页" :total="total" :current="current"
		@change="handlePage" />
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		onShow
	} from '@dcloudio/uni-app';
	import {
		HOST
	} from "../../static/js/const";

	let listData = ref([]);
	let total = ref(0);
	let current = ref(1);
	let pageSize = ref(10);

	const handlePage = (params) => {
		current.value = params.current;
		onQuery()
	}

	const onQuery = () => {
		uni.request({
			url: `${HOST}/task/order/step/alreadyDone`,
			method: 'POST',
			header: {
				'content-type': 'application/json',
				'Authorization': 'Bearer ' + uni.getStorageSync('accessToken')
			},
			data: {
				current: current.value,
				size: pageSize.value,
				data: {
					alarmType: ""
				}
			},
			success: (res) => {
				if (res.data.status === "OK" && res.data.flag) {
					listData.value = res.data.data.records;
					total.value = res.data.data.total;
				} else if (Number(res.data.code) === 401) {
					uni.showToast({
						title: "登录超时",
						icon: "error",
					});
					uni.removeStorageSync("accessToken");
					uni.reLaunch({
						url: "/pages/login/index", // 这里的URL是登录页面的路径
					});
				} else {
					uni.showToast({
						title: res.data.message,
						icon: "error",
					});
				}
			},
			fail: (err) => {
				console.error('请求失败', err);
				uni.showToast({
					title: "连接失败",
					icon: "error"
				});
			}
		});
	}

	onShow(() => {
		onQuery();
	})
</script>

<style lang="scss" scoped>

</style>